#include "task.h"
#include "_p/taskprivate.h"

namespace Opl { namespace Core {



Task::Task(Task *parent) :
	EntityObject(parent), O_PRIVATE_NAME(new TaskPrivate(this))
{
	O_D(Task);
	connect(d, SIGNAL(finished()), SIGNAL(done()));
	connect(d, SIGNAL(terminated()), SIGNAL(done()));
}

Task::~Task()
{
	qDebug() << "Task Destroy:" << toString();
	O_PRIVATE_DELETE;
}

void Task::start()
{
	O_D(Task);
	d->shouldStop = false;
	d->start();
}

void Task::sleep(unsigned long seconds)
{
	TaskPrivate::sleep(seconds);
}

void Task::msleep(unsigned long milliseconds)
{
	TaskPrivate::msleep(milliseconds);
}


void Task::stop()
{
	O_D(Task);
	d->shouldStop = true;
	d->exit(0);
}

void Task::terminate()
{
	O_D(Task);
	d->terminate();
}

void Task::exec()
{
	O_D(Task);
	d->shouldStop = false;
	d->exec();
}

void Task::quit()
{
	O_D(Task);
	d->quit();
}

bool Task::quitNow()
{
	O_D(Task);
	return d->shouldStop;
}

QString Task::toString()
{
	O_D(Task);
	return EntityObject::toString();
}

}}
